<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
  $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
  
  var zNodes;
  var zTreeObj;
  var setting = {
  	check: {
  		enable: true,//显示checkbox
  		chkStyle: "checkbox",
  		chkboxType: { "Y": "p", "N": "s" }
  	},
  	view : {
  		selectedMulti: false
  	},
  	data: {
		key: {
			children: "roleId",
			name: "roleName"
		}
	},
  	callback: {
		onCheck: zTreeOnCheck
	}
  };
$(function(){
	$.ajax({
		type: "POST", 
		url: rootPath + "/sysRole/selectSysRole.do",
		data: '',
		dataType: "json",
		success: function(data){
			zNodes=data;
		      	zTreeObj = $.fn.zTree.init($("#roleTree"), setting, zNodes); 
		}
	  });
});
  
function zTreeOnCheck(event, treeId, treeNode) {
    $("#roleId2").val(treeNode.roleId);
};

$(function(){
	xf.admin.menu${OP.menuId}.update = function(obj) {
  		if($("#menu${OP.menuId}roleForm").valid()){
  			$.ajax({
				type: "POST", 
				url: rootPath + "/op_update_${OP.menuId}.do",
				data: $('#menu${OP.menuId}roleForm').serializeArray(),
				dataType: "json",
				success: function(data){
					if(data.success) {
						xf.closeWindow();
						$('#admin_menu${OP.menuId}_datagrid').bootstrapTable('refresh');
					}
					xf.toastrsAlert({
		       		     code: data.success ? 'success' :'error',
		       		     msg: data.msg
		       		});
				}
			});
  		}
  		
	}  
  });
</script>

<div class="ibox float-e-margins animated fadeInRight">
	<div class="ibox-content">
		<form class="form-horizontal m-t required-validate"
			id="menu${OP.menuId}roleForm" action="op_update_${OP.menuId}.do"
			method="post">
			<input type="hidden" name="userId" value="${dto.userId}" />
			<input type="hidden" name="roleId" id="roleId2"/>
			<div class="form-group">
				<div class="col-sm-8">
				    <label class="col-sm-3 control-label">角色选择：</label>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-8">
			        <ul id="roleTree" class="ztree"></ul>
			    </div>
			</div>
		</form>
	</div>
</div>
